package one.bugu.android.demon.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import one.bugu.android.demon.R;
import one.bugu.android.demon.constant.Constant;
import one.bugu.android.demon.ui.activity.WarnMainActivity;
import one.bugu.android.demon.util.IntentUtils;

public class DialogSnatch extends Dialog {

    private Context mContext;
    private ImageView iv_snatch_close;
    private TextView tv_snatch_btn;


    public DialogSnatch(@NonNull Context context) {
        super(context);
        this.mContext = context;
        initView();
    }

    public DialogSnatch(@NonNull Context context, int themeResId) {
        super(context, themeResId);
        this.mContext = context;
        initView();
    }

    protected DialogSnatch(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
        this.mContext = context;
        initView();
    }

    private void initView() {
        View view = View.inflate(mContext, R.layout.dialog_snatch, null);
        setContentView(view);
        iv_snatch_close = view.findViewById(R.id.iv_snatch_close);
        tv_snatch_btn = view.findViewById(R.id.tv_snatch_btn);

        Window dialogWindow = getWindow();
        dialogWindow.setGravity(Gravity.CENTER);
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        WindowManager wm = this.getWindow().getWindowManager();
        int width = wm.getDefaultDisplay().getWidth();
        lp.width = width - 100;
        dialogWindow.setAttributes(lp);

        tv_snatch_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                IntentUtils.startAty(mContext, SnatchActivity.class);
                IntentUtils.startAty(mContext, WarnMainActivity.class, Constant.ID, 0);
                DialogSnatch.this.dismiss();

            }
        });
        iv_snatch_close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DialogSnatch.this.dismiss();
            }
        });
    }
}
